<script setup>
    import * as echarts from 'echarts'
    import {onMounted} from "vue";
    import {ref} from "vue";
    import chartApi from "@/api/chart.js";

    const chartRef = ref()
    onMounted(() => {
        const myChart = echarts.init(chartRef.value);
        chartApi.selectEarning().then((result) => {
            if (result.code === 0) {
                const option = {
                    title: {
                        text: '销售效益统计',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '药品',
                            type: 'pie',
                            radius: ['40%', '70%'],
                            avoidLabelOverlap: false,
                            label: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    fontSize: 40,
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            data: result.data
                        }
                    ]
                };

                //使用刚制定的配置项和数据显示图表。
                myChart.setOption(option);
            }
        })
    })
</script>

<template>
    <div ref="chartRef" style="width: 100%;height: 100%"></div>
</template>

<style scoped>

</style>